<template>
  <el-dialog @close="hClose" title="分配权限" :visible="isShowAssignDialog">
    <el-tree
      ref="tree"
      node-key="id"
      :data="permList"
      default-expand-all
      show-checkbox
      check-strictly
      :props="{ label: 'name' }"
    />
    <el-button  @click="hSava">确认</el-button>
  </el-dialog>
</template>

<script>
import { getpermission, assignPrem } from '@/api/permission'
import { arrTree } from '@/utils'
import { getPermissById } from '@/api/role'
export default {
  props: {
    isShowAssignDialog: {
      type: Boolean,
      required: true
    },
    curId: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      permList: []
    }
  },
   created() {
    this.loadPermission()
  },
  methods: {
    async hSava() {
      const key = this.$refs.tree.getCheckedNodes()
      await assignPrem({ id: this.curId, permIds: key })
      this.$message.success('更新成功')
      this.hClose()
    },
    async getPermiss() {
      const res = await getPermissById(this.curId)
      console.log(res)
      this.$refs.tree.setCheckedKeys(res.data.permIds)
    },
    async loadPermission () {
    const res = await getpermission()
      const dd = arrTree(res.data, 0)
      this.permList = dd
    },
    hClose() {
      this.$emit('update:isShowAssignDialog', false)
    }
  }
}
</script>

<style>

</style>